package final2107.day05;

import java.util.Arrays;

public class BubbleSort {
    public static void main(String[] args) {
//        int[] ary = {23,12,5,56,0,8,15};
//        //使用冒泡排序对数组进行升序排列
//        for (int i=0;i<ary.length-1;i++){  //比较轮数
//            for (int j=0;j<ary.length-1-i;j++){  //比较元素的下标
//                if (ary[j]>ary[j+1]){
//                    int tmp = ary[j];
//                    ary[j] = ary[j+1];
//                    ary[j+1] = tmp;
//                }
//            }
//        }
//        System.out.println(Arrays.toString(ary));

        String[] ary = {"tom","tony","amy","jack","rose","lily"};
        //升序排列
        for (int i=0;i<ary.length-1;i++){
            for (int j=0;j<ary.length-1-i;j++){
                if (ary[j].compareTo(ary[j+1])>0){
                    String tmp = ary[j];
                    ary[j] = ary[j+1];
                    ary[j+1] = tmp;
                }
            }
        }
        System.out.println(Arrays.toString(ary));



    }
}
